Page({
  data: {
    userInfo: {
      avatar: '',
      nickName: '',
    },
  },
  onShow() {
    this.getUserInfo()
  },
  async getUserInfo() {
    const { code, data: userInfo } = await wx.http.get('/userInfo')
    if (code !== 10000) return wx.utils.toast('获取个人信息失败~')
    this.setData(
      {
        userInfo,
      },
      () => {
        // 存储用户信息到本地
        wx.setStorageSync('userInfo', userInfo)
      }
    )
  },
})
